package cn.sanenen.dm.base;

import cn.hutool.log.Log;
import cn.sanenen.dm.common.Constant;

import java.net.URL;

public class DmApiHelper {
    private static final Log log = Log.get();

    private static volatile DmApi instance;

    private DmApiHelper() {
    }

    public static DmApi getInstance() {
        if (instance == null) {
            synchronized (DmApiHelper.class) {
                if (instance == null) {
                    initDMPlugin();
                }
            }
        }
        return instance;
    }

    private static void initDMPlugin() {
        instance = DMRegHandler.newDmObject(DmApi.class);
//        URL systemResource = ClassLoader.getSystemResource("");
//        System.out.println("systemResource = " + systemResource==null);
//        String classpathRoot = ClassLoader.getSystemResource("").getPath();
//        if (classpathRoot.startsWith("/") && classpathRoot.contains(":")) {
//            classpathRoot = classpathRoot.substring(1); // 去掉开头的 /
//        }
//        instance.SetPath(classpathRoot + Constant.DM_FILES);
        instance.SetPath(Constant.DM_FILES);
        long reg = instance.Reg("826980bda1470e5da3819d63d9c432b16162d8", "");
        if (reg == 1) {
            log.info("初始化大漠插件成功");
        }
    }
}
